package com.want.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author WangZhiJian
 * @since 2021/12/16
 */
@Configuration
@EnableConfigurationProperties(OssConfiguration.OssProperties.class)
public class OssConfiguration {


    @Bean
    public OSS ossClient(OssProperties ossProperties){
        OSS ossClient = new OSSClientBuilder().build(ossProperties.getEndpoint(), ossProperties.getAccessKeyId(), ossProperties.getAccessKeySecret());
        return ossClient;
    }

    @Data
    @ConfigurationProperties("com.want.oss")
    public static class OssProperties {
        private String endpoint;
        private String accessKeyId;
        private String accessKeySecret;
        // kb 为单位
        private Integer limitSpeed = 300;
        private String bucket;
        private String basePath;
    }
}
